package com.mpsc.current.controller;


import com.mpsc.api.bean.RoleInfoEntity;
import com.mpsc.api.common.BaseResponse;
import com.mpsc.current.annotation.CacheLock;
import com.mpsc.current.annotation.CacheParam;
import com.mpsc.current.config.spi.DataSpi;
import com.mpsc.current.service.RoleInfoService;
import com.mpsc.current.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ServiceLoader;

@RestController
@RequestMapping("/roleInfo")
@Api(value = "RoleInfoController", tags = "角色管理")
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;

    @PatchMapping("/save")
    @ApiOperation("保存用户信息")
    public void save(@RequestBody RoleInfoEntity role) {
        roleInfoService.saveRoleInfo(role);
    }

    @CacheLock(prefix = "select_role")
    @PostMapping("/select")
    @ApiOperation("查询用户信息")
    public BaseResponse select(@RequestBody RoleVo role) {
        System.out.println(role.toString());
        return new BaseResponse(001002,"疯狂小豆丁",null);
    }

    @CacheLock(prefix = "select_role_one")
    @GetMapping("/select-one")
    @ApiOperation("查询用户信息")
    public BaseResponse selectOne(@CacheParam(name = "name") @RequestParam String name) {
        System.out.println(name);
        return new BaseResponse(001002,"疯狂小豆丁",null);
    }


    public static void main(String[] agrs) {
        ServiceLoader<DataSpi> loaders = ServiceLoader.load(DataSpi.class);
        for (DataSpi helloService : loaders) {
            helloService.TestSpi();
        }
    }

}
